package service.impl;


import java.math.BigDecimal;
import java.util.List;

import com.github.pagehelper.PageHelper;
import dao.RoleMapper;
import dao.UserMapper;
import model.Menu;
import model.Role;
import model.User;
import org.springframework.stereotype.Service;
import service.UserServiceI;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2016/6/14.
 */
@Service
public class UserServiceImpl implements UserServiceI {
    @Resource
    private UserMapper userMapper;
    @Resource
    private RoleMapper roleMapper;


    public User findUser(User user) {
        List<User> list = userMapper.selectByUser(user);
        if(list.isEmpty()){
            return null;
        }else{
            return list.get(0);
        }
    }

    public int getUserCount(User user) {
        return userMapper.getUserCount(user);
    }

    public List<User> getUser(int pageNow, int pageSize, User user,String oeder) {
        PageHelper.startPage(pageNow, pageSize);
        PageHelper.orderBy(oeder);
        List<User> list = (List<User>) userMapper.getUser();
        return list;
    }

    public int saveUser(User user) {
        return userMapper.insertSelective(user);
    }

    public User getUserById(BigDecimal userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

    public int updateUserById(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }

    public List<Menu> getMenuByUserId(BigDecimal userId) {
        Role role = roleMapper.
        return null;
    }
}
